/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.dataaccess.hibernate;

import cms.dataaccess.ReviewRateDAO;
import cms.exceptions.HibernateAccessLayerException;
import dto.Reviewrate;
import dto.ReviewrateId;
import java.util.List;

/**
 *
 * @author Gary
 */
class ReviewRateDAOImpl extends AbstractDAO implements ReviewRateDAO {
    
    public ReviewRateDAOImpl() {
        super();
    }

    @Override
    public Reviewrate getReviewRate(String catID, int rate) {
          try{
             List< Reviewrate> rlist =  this.findByCustomizeQuery(Reviewrate.class, "catID='"+catID + "' and rateValue="+rate);
             if(rlist.size() <=0 ){
                 return null;
             } 
             
             return rlist.get(0);
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    }

    @Override
    public List<Reviewrate> getReviewRates(String catID) {
        
      
         try{
             List< Reviewrate> rlist =  this.findByCustomizeQuery(Reviewrate.class, "catID='"+catID + "'");
             if(rlist.size() <=0 ){
                 return null;
             } 
             
             return rlist;
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    }

    @Override
    public boolean updateReviewRate(Reviewrate rate) {
        if(rate== null){
            return false;
        }
        
          try{
              
          this.saveOrUpdate(rate);
          return true;
            } catch (Throwable t)
            {
            throw new HibernateAccessLayerException(t.toString());
            }
    }

    @Override
    public boolean deleteReviewRate(String catID, int rate) {
       if(catID== null){
            return false;
        }
        
            try{
              Reviewrate ratereview=  this.getReviewRate(catID, rate);
              this.delete(ratereview);
              return true;
            } catch (Throwable t)
            {
            throw new HibernateAccessLayerException(t.toString());
            }
    }

    @Override
    public List<Reviewrate> getAllReviewRates() {
          try{
              return  this.findAll(Reviewrate.class);
             
            } catch (Throwable t)
            {
            throw new HibernateAccessLayerException(t.toString());
            }
        
    }


}
